<div class="layui-form" id="list-select" lay-title="代理分组">
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15" style="margin-top: 0;">
      <div class="layui-col-md12">
        <div class="layui-card" style="box-shadow: none;">
          <div class="layui-card-body">
			<div>
				<button class="layui-btn layuiadmin-btn-lists" data-type="add">添加</button>
			</div>
            <table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>
			<script type="text/html" id="list-select-toolbar">
			  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</script>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="form-btn">
  	<input type="button" value="确认选择" class="layui-btn selectok">
   </div>
</div>
<script>
   //表格数据渲染
  var formurls='agent_group/agent_groupform',formareas=['500px', '200px'];
  layui.use(['table','form'], function () {
	  var table = layui.table
	  ,form = layui.form
	  ,$ = layui.$;
	  layui.admin.initlist(table,'agents/get_group_list',195,[[
		{type:'radio'}
        ,{field:'group_id', title: 'ID', width:100}
        ,{field:'agent_group_name', title: '分组名称', width:200}
        ,{field:'create_time', title: '创建时间', width: 200}
		,{title:'操作', toolbar: '#list-select-toolbar', width:200}
      ]],'#list-select-table',415,{obj:layui.admin.agent,val1:'group_id',val2:'agent_group_id'})
	//监听表格操作事件
	table.on('tool(list-select-table)', function(obj){
	  var data = obj.data;
	  //删除
	  if(obj.event === 'del'){

		layer.confirm('确定删除'+data.agent_group_name+'?', function(index){
		  layui.admin.ajax('agents/group_delete',{agent_group_id:data.group_id}).then(function(res){
			  layui.table.reload('list-select-table');
		  })
		});
	  } else if(obj.event === 'edit'){//编辑
          layui.admin.pupsc=layer.open({
              type:1,
              id:'pup-contss',
              title: '编辑分组',
              btn:[],
              area: formareas,
              success: function(layero, index){
                  layui.admin.objDatas={detail:data,type:2};
                  $('#pup-contss').load(layui.conf.views+formurls+layui.conf.engine);
              }
          })
	//	layui.admin.pupF('编辑分组',formarea,formurl,1,data)
		//layui.admin.pupF('添加代理分组',formarea,formurl,1,{})
	  }
	});
	var active = {add: function(othis){
		layui.admin.pupsc=layer.open({
			type:1,
		   id:'pup-contss',
		   title: '添加代理分组',
		   btn:[],
		   area: formareas,
		   success: function(layero, index){
               layui.admin.objDatas={type:1};
			$('#pup-contss').load(layui.conf.views+formurls+layui.conf.engine);
		   }
		})
	  }
	}; 
	//操作dom
	$('.layui-btn.layuiadmin-btn-lists').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
	});
	$('.selectok').click(function(){
			var checkStatus = table.checkStatus('list-select-table')
			,checkData = checkStatus.data[0];
			if(!checkData){
				layer.msg('请选择分组');
			}else{
				layui.admin.agent.agent_group_id=checkData.group_id;
				layui.admin.agent.agent_group_name=checkData.agent_group_name;
				layer.close(layui.admin.pups);
			}
		});
  });
</script>